package nz.ac.massey.groupproject.ecs2;

public class UserControlledMotionSystem implements ECSSystem {

	public void tick(GameState state, Position pos, UserControlledMotion just_a_tag) {
		final int  MIN_X = state.MINX,  MAX_X = state.MAXX;
		final int  MIN_Y = state.MINY,  MAX_Y = state.MAXY;
		int  dx = state.playerMovDirDX,  dy = state.playerMovDirDY;

		int spd = (dx != 0 && dy != 0) ? 4 : 5;
		pos.x += dx * spd;
		pos.y += dy * spd;
		if (pos.x < MIN_X) pos.x = MIN_X; if (pos.x > MAX_X) pos.x = MAX_X;
		if (pos.y < MIN_Y) pos.y = MIN_Y; if (pos.y > MAX_Y) pos.y = MAX_Y;
	}
}
